package com.xzx.annotation.config;

import com.xzx.annotation.bean.Person;
import com.xzx.annotation.bean.Person02;
import com.xzx.annotation.bean.Person06;
import com.xzx.annotation.custom.*;
import com.xzx.annotation.repository.Repository02;
import com.xzx.annotation.service.Service01;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * @author xinzhixuan
 * @version 1.0
 * @date 2025/3/15 10:40
 */
@ComponentScan(value = "com.xzx",
        excludeFilters = {
                @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {
                        Controller.class
                }),
                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {
                        Service01.class
                }),
                @ComponentScan.Filter(type = FilterType.CUSTOM, classes = {
                        MyScanFilter.class
                })
        })
@Configuration
@Import({Person02.class, MyImportSelector.class, MyImportBeanDefinitionRegistrar.class})// com.xzx.annotation.bean.Person02
public class MainConfig {

    @Conditional(MyCondition.class)
    @Lazy
    @Bean
    public Person person() {
        Person person = new Person();
        person.setName("xzx");
        return person;
    }

    @Bean
    public Person05FactoryBean person05FactoryBean() {
        return new Person05FactoryBean();
    }

    @Bean(initMethod = "init1", destroyMethod = "destroy1")
    public Person06 person06() {
        return new Person06();
    }

    @Primary
    @Bean
    public Repository02 repository() {
        Repository02 repository02 = new Repository02();
        repository02.setName("002");
        return repository02;
    }
}
